<?php require_once('Connections/locamedicadmin.php'); ?>

<?php include('userValidation.php'); ?>

<?php require_once('functions.php'); ?>

<?php

$currentPage = $_SERVER["PHP_SELF"];

$maxRows_categories = 20;
$pageNum_categories = 0;
if (isset($_GET['pageNum_categories'])) {
  $pageNum_categories = $_GET['pageNum_categories'];
}
$startRow_categories = $pageNum_categories * $maxRows_categories;

mysql_select_db($database_locamedicadmin, $locamedicadmin);
$query_categories = "SELECT * from csre_category";
$query_limit_categories = sprintf("%s LIMIT %d, %d", $query_categories, $startRow_categories, $maxRows_categories);
$categories = mysql_query($query_limit_categories, $locamedicadmin) or die(mysql_error());
$row_categories = mysql_fetch_assoc($categories);

if (isset($_GET['totalRows_categories'])) {
  $totalRows_categories = $_GET['totalRows_categories'];
} else {
  $all_categories = mysql_query($query_categories);
  $totalRows_categories = mysql_num_rows($all_categories);
}
$totalPages_categories = ceil($totalRows_categories/$maxRows_categories)-1;

$queryString_categories = "";
if (!empty($_SERVER['QUERY_STRING'])) {
  $params = explode("&", $_SERVER['QUERY_STRING']);
  $newParams = array();
  foreach ($params as $param) {
    if (stristr($param, "pageNum_categories") == false && 
        stristr($param, "totalRows_categories") == false) {
      array_push($newParams, $param);
    }
  }
  if (count($newParams) != 0) {
    $queryString_categories = "&" . htmlentities(implode("&", $newParams));
  }
}
$queryString_categories = sprintf("&totalRows_categories=%d%s", $totalRows_categories, $queryString_categories);
?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Locamedic CSRE Admin</title>
<link href="locamedicadmin.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="page">

	<?php include('sidebar.php'); ?>
	
	<!-- end sidebar -->
	<div id="content">
		<div align="center"><img src="images/page_image_5.jpg" alt="" /></div>
	  <div class="boxed">
		<h1 class="title2">Liste des Categories</h1>
		<br />
		<?php if (isset($_GET['categoryused'])) { ?>		
		<table>
			<tr>
				<td>
					<table>
						<tr>
							<td width="30">
								<img src="images/redCross.png" />
							</td>
							<td>
								Impossible de supprimer la categorie selectionne,car est affecte a un ou plusieurs produits.
							</td>
						</tr>
					</table>
				</td>
			</tr>
		</table>
		<?php } ?>	
		<?php if ($totalRows_categories > 0) { ?>
		<table cellpadding="5" cellspacing="0">
		  <thead>
		    <td>Categorie</td>
			<td width="5%"></td>
			<td width="5%"></td>
		 </thead>
		  <?php do { ?>
			<tr>
			  <td><?php echo $row_categories['name_' . $lang]; ?></td>
			  <td align="center">
				<a href="category_edit.php?categoryid=<?php echo $row_categories['category_id']; ?>">
					<img src="images/1307905892_desktop.png" alt="Modifier" border="0" />
				</a>
			  </td>
			  <td align="center">
				<a href="category_delete.php?categoryid=<?php echo $row_categories['category_id']; ?>" 
					onclick="return confirm('Etes-vous sûr de vouloir supprimer ce registre?');">
					<img src="images/1307905898_edit-trash.png" alt="Supprimer" border="0" />
				</a>
			  </td>
			</tr>
			<?php } while ($row_categories = mysql_fetch_assoc($categories)); ?>
		</table>
		<table>
			<tr>
				<td align="center">
					Rows <?php echo ($startRow_categories + 1) ?> to <?php echo min($startRow_categories + $maxRows_categories, $totalRows_categories) ?> of <?php echo $totalRows_categories ?>
				</td>
			</tr>
		</table>
		       

		
		<table border="0" width="50%" align="center">
          <tr>
            <td width="23%" align="center"><?php if ($pageNum_categories > 0) { // Show if not first page ?>
                  <a href="<?php printf("%s?pageNum_categories=%d%s", $currentPage, 0, $queryString_categories); ?>"><img src="images/resultset_first.png" border=0></a>
                  <?php } // Show if not first page ?>
            </td>
            <td width="31%" align="center"><?php if ($pageNum_categories > 0) { // Show if not first page ?>
                  <a href="<?php printf("%s?pageNum_categories=%d%s", $currentPage, max(0, $pageNum_categories - 1), $queryString_categories); ?>"><img src="images/resultset_previous.png" border=0></a>
                  <?php } // Show if not first page ?>
            </td>
            <td width="23%" align="center"><?php if ($pageNum_categories < $totalPages_categories) { // Show if not last page ?>
                  <a href="<?php printf("%s?pageNum_categories=%d%s", $currentPage, min($totalPages_categories, $pageNum_categories + 1), $queryString_categories); ?>"><img src="images/resultset_next.png" border=0></a>
                  <?php } // Show if not last page ?>
            </td>
            <td width="23%" align="center"><?php if ($pageNum_categories < $totalPages_categories) { // Show if not last page ?>
                  <a href="<?php printf("%s?pageNum_categories=%d%s", $currentPage, $totalPages_categories, $queryString_categories); ?>"><img src="images/resultset_last.png" border=0></a>
                  <?php } // Show if not last page ?>
            </td>
          </tr>
        </table>
		<?php } else { ?>
		<table>
			<tr>
				<td>Pas de categories trouvies</td>
			</tr>
		</table>
		<?php } ?>
        <div class="botonera">
			<input type="button" onclick="window.location='category_add.php';" value="Ajouter une Categorie" />
		</div>
		
	  </div>
  </div>
	<!-- end content -->
	<div style="clear: both;">&nbsp;</div>
</div>
<!-- end page -->

<?php include('footer.php'); ?>

</body>
</html>
<?php
mysql_free_result($categories);
?>